package cn.net.yugu.doraemon.netty.protocol.msg22;

import cn.net.yugu.doraemon.netty.protocol.MsgCode;
import io.netty.buffer.ByteBuf;
import org.apache.commons.codec.DecoderException;
import org.apache.commons.codec.binary.Hex;

/**
 * 取数数据更新
 */
public class Msg222000008 extends Msg222 {
    public String cabinetId;
    public byte status;
    public byte num;

    @Override
    public int getMsgCode() {
        return MsgCode.MSG_222000008.getCode();
    }

    @Override
    public void readData(ByteBuf buffer) {
        readRtn(buffer);

        byte[] bytes = new byte[12];
        buffer.readBytes(bytes);
        cabinetId = new String(bytes, CHARSET_UTF_8);
        status = buffer.readByte();
        num = buffer.readByte();
    }

    @Override
    public void writeData(ByteBuf buffer) {
		writeRtn(buffer);

        try {
            buffer.writeBytes(Hex.decodeHex(cabinetId.toCharArray()));
        } catch (DecoderException e) {
            e.printStackTrace();
        }
		buffer.writeByte(status);
		buffer.writeByte(num);
    }
}
